home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: A question on for loop..
- Date: 12 Mar 1996 07:02:40 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4i43mgINNm3m@keats.ugrad.cs.ubc.ca>
- References: <4hn80a$98q@male.EBay.Sun.COM>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <4hn80a$98q@male.EBay.Sun.COM>,
- Murali Chari <murali@sooraj.ebay.sun.com> wrote:
- >Hi,
- >
- >In the following piece of code:
- >
- >for(i=0;i< 20; i++)
- >
- >{
- >
- >
- >
- > if(condition==FALSE)
- > continue;
- >
- >
- >
- >
- >}
- >
- >Let us assume i=10 before it entered the loop.
-
- What does it matter what i was before the loop? It gets initialized to zero.
-
- >The condition was false. So the continue statement
- >got executed.
- >
- >Will control now go to the third statement in the for loop?
-
- The for loop does not contain statements. It contains expressions; if it
- contained statements, you would be able to write compounds and things like
- while(...) constructs in there.
-
-
- >i.e. will i be incremented by 1 and again tested for the condition?
-
- Yes; ``continue'' causes the the increment step to be executed.
-
- If you check the K&R2 appendix A, section 9.5, you will note that:
-
-
- for ( expression1 ; expression2 ; expression 3 ) statement
-
- is equivalent to
-
- expression1 ;
- while ( expression2 ) {
- statement
- expression3 ;
- }
-
- IF the substatement does not contain a ``continue''.
-
- With a continue (and this is not written up in K&R), the equivalent of the
- continue statement would be like a ``goto contin;'' in the following, except
- that the contin: label is just conceptual; the actual mechanism doesn't involve
- the use a statement label:
-
- expression1 ;
- while ( expression2 ) {
- statement
- contin:
- expression3 ;
- }
- --
-
-